package net.crowdloud.server.DatabaseAccess.problem;

import javax.jdo.PersistenceManager;

import net.crowdloud.server.DatabaseAccess.user.GetUser;
import net.crowdloud.server.DatabaseAccess.user.User;

public class SaveProblem {

	public static void addNew(PersistenceManager persistenceManager,
			Long userID, net.crowdloud.shared.entities.Problem problem, String tags) {

		User userDatabase = GetUser.getUserDatabase(persistenceManager, userID);

		userDatabase.getUserProblems().add(
				ConvertProblemToDatabase.getDatabaseProblem(new Problem(),
						problem, tags));

		persistenceManager.makePersistent(userDatabase);
	}

	public static void update(PersistenceManager persistenceManager,
			net.crowdloud.shared.entities.Problem problem, String tags) {

		Problem problemDatabase = GetProblem.getProblemDatabase(
				persistenceManager, problem.getProblemID());

		ConvertProblemToDatabase.getDatabaseProblem(problemDatabase, problem,
				tags);

		persistenceManager.makePersistent(problemDatabase);
	}
}
